package com.usfuture.util
{

	public class DateTimeUtils
	{

		public static function str2Date(str:String):Date
		{
			
			return new Date(parseFloat(str.substr(0, 4)), 
							parseFloat(str.substr(4, 2))-1, 
							parseFloat(str.substr(6, 2)), 
							parseFloat(str.substr(8, 2)),
							parseFloat(str.substr(10, 2)), 
							parseFloat(str.substr(12, 2)));
		}
		
		/**
		 * 把日期转化为字符串
		 * @param date
		 * @param format 0:yyyyMMddHHmmss,1:yyyy-MM-dd HH:mm:ss,2:yyyy/MM/dd HH:mm:ss,
		 * @return 
		 */
		public static function date2Str(date:Date,format:uint=0):String
		{
			var year:String = date.getFullYear()+'';
			var month:String = (date.month+1)>=10?''+(date.month+1):'0'+(date.month+1);
			var day:String = date.date>=10?''+date.date:'0'+date.date;
			var hour:String = date.hours>=10?''+date.hours:'0'+date.hours;
			var minute:String = date.minutes>=10?''+date.minutes:'0'+date.minutes;
			var second:String = date.seconds>=10?''+date.seconds:'0'+date.seconds;
			var dateStr:String;
			switch(format){
				case 0:dateStr = year+month+day+hour+minute+second; break;
				case 1:dateStr = year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second; break;
				case 2:dateStr = year+"/"+month+"/"+day+" "+hour+":"+minute+":"+second; break;
				default:dateStr = year+month+day+hour+minute+second; break;
			}
			return dateStr;
		}
	}
}